package com.ocean.productDict.service.impl;

import java.util.*;

import com.ocean.common.core.domain.entity.SysUser;
import com.ocean.common.utils.ShiroUtils;
import com.ocean.common.utils.uuid.IdUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ocean.productDict.mapper.OForecastIntervalMapper;
import com.ocean.productDict.domain.OForecastInterval;
import com.ocean.productDict.service.IOForecastIntervalService;
import com.ocean.common.core.text.Convert;

/**
 * 预报间隔维护Service业务层处理
 *
 * @author ocean
 * @date 2023-01-05
 */
@Service
public class OForecastIntervalServiceImpl implements IOForecastIntervalService
{
    @Autowired
    private OForecastIntervalMapper oForecastIntervalMapper;

    /**
     * 查询预报间隔维护
     *
     * @param id 预报间隔维护主键
     * @return 预报间隔维护
     */
    @Override
    public OForecastInterval selectOForecastIntervalById(String id)
    {
        return oForecastIntervalMapper.selectOForecastIntervalById(id);
    }

    /**
     * 查询预报间隔维护列表
     *
     * @param oForecastInterval 预报间隔维护
     * @return 预报间隔维护
     */
    @Override
    public List<OForecastInterval> selectOForecastIntervalList(OForecastInterval oForecastInterval)
    {
        return oForecastIntervalMapper.selectOForecastIntervalList(oForecastInterval);
    }

    /**
     * 新增预报间隔维护
     *
     * @param oForecastInterval 预报间隔维护
     * @return 结果
     */
    @Override
    public int insertOForecastInterval(OForecastInterval oForecastInterval)
    {
        oForecastInterval.setId(IdUtils.simpleUUID());
        SysUser sysUser = ShiroUtils.getSysUser();
        oForecastInterval.setCreateName(sysUser.getUserName());
        oForecastInterval.setCreateBy(sysUser.getLoginName());
        oForecastInterval.setCreateDate(new Date());
        oForecastInterval.setDepartId(sysUser.getDeptId().toString());
        return oForecastIntervalMapper.insertOForecastInterval(oForecastInterval);
    }

    /**
     * 修改预报间隔维护
     *
     * @param oForecastInterval 预报间隔维护
     * @return 结果
     */
    @Override
    public int updateOForecastInterval(OForecastInterval oForecastInterval)
    {
        SysUser sysUser = ShiroUtils.getSysUser();
        oForecastInterval.setUpdateName(sysUser.getUserName());
        oForecastInterval.setUpdateBy(sysUser.getLoginName());
        oForecastInterval.setUpdateDate(new Date());
        return oForecastIntervalMapper.updateOForecastInterval(oForecastInterval);
    }

    /**
     * 批量删除预报间隔维护
     *
     * @param ids 需要删除的预报间隔维护主键
     * @return 结果
     */
    @Override
    public int deleteOForecastIntervalByIds(String ids)
    {
        return oForecastIntervalMapper.deleteOForecastIntervalByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除预报间隔维护信息
     *
     * @param id 预报间隔维护主键
     * @return 结果
     */
    @Override
    public int deleteOForecastIntervalById(String id)
    {
        return oForecastIntervalMapper.deleteOForecastIntervalById(id);
    }

    @Override
    public Map<String, List> getNameAndCode() {
        Map<String, List> result = new HashMap<>();
        List<OForecastInterval> list = oForecastIntervalMapper.selectOForecastIntervalList(new OForecastInterval());
        List<String> names = new ArrayList<>();
        List<String> codes = new ArrayList<>();
        for (OForecastInterval interval : list) {
            names.add(interval.getName());
            codes.add(interval.getCode());
        }
        result.put("names",names);result.put("codes",codes);
        return result;
    }
}
